package com.qiyang.lambda;

import java.text.DecimalFormat;
import java.util.function.Function;

//interface IMoneyFormat {
//    String format(int i);
//}

class MyMoney {
    private final int money;

    public MyMoney(int money) {
        this.money = money;
    }

    //    public void printMoney(IMoneyFormat iMoneyFormat) {
//        System.out.println("我的存款：" + iMoneyFormat.format(this.money));
//    }
    public void printMoney(Function<Integer, String> moneyFormat) {
        System.out.println("我的存款：" + moneyFormat.apply(this.money));
    }

}

/**
 * Created on 2018/8/4.
 *
 * @author sehuaqi.
 * 描述：
 */
public class MoneyDemo {

    public static void main(String args[]) {
    	//执行函数
        MyMoney money = new MyMoney(500000000);
        money.printMoney(i -> new DecimalFormat("#,###").format(i));

        Function<Integer, String> moneyFormat = i -> new DecimalFormat("#,###").format(i);

        //函数接口链式操作
        money.printMoney(moneyFormat.andThen(s -> "RMB " + s));
    }
}
